<?php
namespace app\api\service;

use app\api\model\user\UserManager as UserManagerModels;

/**
 * UserManager Service
 * User: zng
 * Date: 2020/03/02
 * Time: 16:25
 */
class UserManager {

    /**
     * 更新或添加用户阅读
     * @author zx
     * @date 2020-03-02
     * @return bool
     */
    public function set(array $data)
    {
        $userManager = UserManagerModels::where('bcid', $data['bcid'])->findOrEmpty();
        if ( $userManager->isEmpty() === false ) {
	    if($userManager->audio_url){
		app('uploader_service')->delete($userManager->audio_url);
	    }
            $userManager->audio_url = $data['audio_url'];
            return $userManager->save();
        }
        return UserManagerModels::create($data)->id?true:false;
    }

    /**
     * 更新或添加用户阅读
     * @author zx
     * @date 2020-03-02
     * @return bool
     */
    public function score(array $data)
    {
        $userManager = UserManagerModels::where('bcid', $data['bcid'])->findOrEmpty();
        if ( $userManager->isEmpty() === false ) {
            $userManager->score = $data['score'];
            return $userManager->save();
        }
        return UserManagerModels::create($data)->id?true:false;
    }

}
